<?php
declare(strict_types=1);
/**
 * Created by PhpStorm
 * User: Administrator
 * Date: 2022/8/31
 * Time: 16:14:09
 */

namespace app\shop\controller;

use app\common\service\CouponService\CouponService;
use app\Normal;
use think\annotation\Route;
use think\annotation\route\Group;
use think\annotation\route\Middleware;

/**
 * 优惠券
 * @Group("Coupon")
 * @Middleware("{shopMiddileware::class}")
 */
class Coupon extends \app\BaseShopController
{
    /**
     * 优惠券列表
     * @Route("couponLists",method="GET")
     * @return void
     */
    public function couponLists(){
        $result = callApi(CouponService::class,"couponLists",$this->_all_data);
        return apiResponse($result);
    }

    /**
     * 新增优惠券
     * @Route("addCoupon",method="post")
     * @return void
     */
    public function addCoupon(){
        $result = callApi(CouponService::class,"addCoupon",$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'新增名称为【'.$this->_all_data['name'] . '】的优惠券','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 优惠券详情
     * @Route("couponInfo/:id",method="GET")
     * @return void
     */
    public function couponInfo(){
        $result = callApi(CouponService::class,"couponInfo",$this->_all_data);
        return apiResponse($result);
    }

    /**
     * 结束优惠券活动
     * @Route("changeStatus",method="POST")
     * @return void
     */
    public function changeStatus(){
        $result = callApi(CouponService::class,"changeStatus",$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'结束ID为【'.$this->_all_data['id'] . '】的优惠券活动','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 生成券编码
     * @Route("generateCode/:id",method="GET")
     * @return void
     */
    public function generateCode(){
        $result = callApi(CouponService::class,"generateCode",$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'生成ID为【'.$this->_all_data['id'] . '】的优惠券券编码','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 手动优惠券列表
     * @Route("manualCouponLists/:id",method="GET")
     * @return void
     */
    public function manualCouponLists(){
        $result = callApi(CouponService::class,"manualCouponLists",$this->_all_data);
        return apiResponse($result);
    }

    /**
     * 获取优惠券使用店铺列表
     * @Route("getCouponStoreLists/:id",method="GET")
     * @return \think\Response|\think\response\Json
     */
    public function getCouponStoreLists(){
        $result = callApi(CouponService::class,"getCouponStoreLists",$this->_all_data);
        return apiResponse($result);
    }
}